package group2.core.database;

import group2.core.database.impl.CamelUserJpaCtrl;
import group2.core.database.impl.CommentJpaCtrl;
import group2.core.database.impl.PostJpaCtrl;
import group2.core.entities.CamelUser;
import group2.core.entities.Comment;
import group2.core.entities.Post;
import javax.persistence.Persistence;

/**
 * Creates JpaControllers.
 * 
 * @author ludwigk
 */
public class JpaCtrlFactory {
    
    private static JpaCtrlFactory instance;

    private IJpaCtrl<CamelUser> camelUserCtrl = new CamelUserJpaCtrl(null,
            Persistence.createEntityManagerFactory("webblog_pu"));
    private IJpaCtrl<Post> postCtrl = new PostJpaCtrl(null,
            Persistence.createEntityManagerFactory("webblog_pu"));
    private IJpaCtrl<Comment> commentCtrl = new CommentJpaCtrl(null,
            Persistence.createEntityManagerFactory("webblog_pu"));

    private JpaCtrlFactory() {
    }
    
    public static JpaCtrlFactory getInstance(){
        if(instance == null)
            instance = new JpaCtrlFactory();
        return instance;
    }
    
    public IJpaCtrl<CamelUser> getCamelUserCtrl(){
        return camelUserCtrl;
    }
    
    public IJpaCtrl<Post> getPostCtrl(){
        return postCtrl;
    }
    
    public IJpaCtrl<Comment> getCommentCtrl(){
        return commentCtrl;
    }
}
